package com.lingx.model.impl.validator;

import java.util.Map;

import org.springframework.stereotype.Component;

import com.lingx.model.IContext;
import com.lingx.model.impl.AbstractValidator;
import com.lingx.model.impl.DefaultField;
@Component
public class NotEqualsIDValidator  extends AbstractValidator {

	private static final long serialVersionUID = 6280491369572785871L;
	public NotEqualsIDValidator() {
		super("NotEqualsIDValidator", "不等于ID校验");
		this.setComment("不需要额外参数");
		this.setMessage(DEFAULT_MESSAGE+"，不能等于主键");
	}
	@Override
	public boolean valid(Object value,String param,Map<String,Object> params,DefaultField field,IContext context)throws Exception {
		try {
			if(params.containsKey("id")) {
				return !value.toString().equals(params.get("id").toString());
			}else {
				return true;
			}
			
		} catch (Exception e) {
			return false;
		}
	}
}
